package tat.domain.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import tat.domain.AllActors;
import tat.domain.TatActor;

public class AllActorsImpl implements AllActors {

	private Map<String, TatActor> map = new HashMap<String, TatActor>();
	
	@Override
	public void registerActor(String actorName, TatActor actor){
		map.put(actorName, actor);
	}
	
	@Override
	public void removeActor(String actorName) {
		map.remove(actorName);		
	}
	
	@Override
	public TatActor find(String actorName) {
		return map.get(actorName);
	}
	
	@Override
	public TatActor[] conferActors(){
		return map.values().toArray(new TatActor[map.size()]);
	}

	@Override
	public String actorsAsText() {
		String text = "";
		Iterator<TatActor> actors = map.values().iterator();
		while(actors.hasNext()){
			text = text + actors.next().toString();
		}
		return text;
	}

	@Override
	public String actorsAsXML() {
		String text = "";
		Iterator<TatActor> actors = map.values().iterator();
		while(actors.hasNext()){
			text = text + actors.next().toXML();
		}
		return text;
	}

	@Override
	public void remapActor(String oldActorName, TatActor actor) {
		map.remove(oldActorName);
		map.put(actor.name(), actor);
	}


}
